package com.weijianhuawen.wjblog.admin.controller;

import com.weijianhuawen.wjblog.admin.mode.vo.category.AddCategoryReqVo;
import com.weijianhuawen.wjblog.admin.mode.vo.category.DeleteCategoryReqVo;
import com.weijianhuawen.wjblog.admin.mode.vo.category.FindCategoryPageListReqVo;
import com.weijianhuawen.wjblog.admin.service.AdminCategoryService;
import com.weijianhuawen.wjblog.common.aspect.ApiOperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description:
 * @date: 2024-10-19 23:42
 */

@RestController
@RequestMapping("/admin")
@Api(tags = "Admin 分类模块")
public class AdminCategoryController {
    @Autowired
    AdminCategoryService adminCategoryService;

    /**
     * 添加分类标签
     * @param vo
     * @return
     */
    @PostMapping("/category/add")
    @ApiOperation(value = "添加分类")
    @ApiOperationLog(description = "添加分类标签")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Object addCategory(@RequestBody @Validated AddCategoryReqVo vo) {
        return adminCategoryService.addCategory(vo);
    }

    /**
     * 分页查询标签
     * @param vo
     * @return
     */
    @PostMapping("/category/list")
    @ApiOperation(value = "分页查询分类列表")
    @ApiOperationLog(description = "分类查询分类列表")
    public Object findCategoryList(@RequestBody @Validated FindCategoryPageListReqVo vo) {
        return adminCategoryService.findCategoryList(vo);
    }

    /**
     * 通过id删除分类名称
     * @param vo
     * @return
     */
    @PostMapping("/category/delete")
    @ApiOperation(value = "通过id删除分类")
    @ApiOperationLog(description = "根据传入的id删除id")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Object deleteCategory(@RequestBody @Validated DeleteCategoryReqVo vo) {
        return adminCategoryService.deleteCategory(vo);
    }

    @GetMapping("/category/select/list")
    @ApiOperation(value = "查询分类标签")
    @ApiOperationLog(description = "查询所有分类标签")
    public Object findCategorySelectList() {
        return adminCategoryService.findCategorySelectList();
    }
}
